package ee.ut.sysmodel.bgmn.model;

public class Move {
	private Pin source;
	private Pin target;
	
	private DiceResult[] usedDice;
	
	public Move(Pin source, Pin target, DiceResult[] usedDice) {
		this.source = source;
		this.target = target;
		this.usedDice = usedDice;
	}

	public Pin getSource() {
		return source;
	}

	public Pin getTarget() {
		return target;
	}

	public DiceResult[] getUsedDice() {
		return usedDice;
	}
	
	public void useDice() {
		for(DiceResult d : usedDice)
			d.setUsed(true);
	}
	
	public boolean canBeDone() {
		if(source.isOwned() && target.isOwned() && source.getOwner() != target.getOwner() && target.getPieceCount() > 1)
			return false;
		
		for(DiceResult dr : usedDice) {
			if(dr.isUsed())
				return false;
		}
		
		return true;
	}
	
	public String toString() {
		String s =  "(" + source.getNumber() + " -> " + target.getNumber() + " ";
		
		s += "[ ";
		for(DiceResult dice : usedDice) {
			s = s + dice.getResult() + " ";
		}
		s += "])";
		
		return s;
	}
}
